package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.TbShoppingOrder;
import com.ruoyi.system.service.ITbShoppingOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 订单购物车中间Controller
 * 
 * @author ruoyi
 * @date 2024-04-07
 */
@RestController
@RequestMapping("/system/order")
public class TbShoppingOrderController extends BaseController
{
    @Autowired
    private ITbShoppingOrderService tbShoppingOrderService;

    /**
     * 查询订单购物车中间列表
     */
    @PreAuthorize("@ss.hasPermi('system:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbShoppingOrder tbShoppingOrder)
    {
        startPage();
        List<TbShoppingOrder> list = tbShoppingOrderService.selectTbShoppingOrderList(tbShoppingOrder);
        return getDataTable(list);
    }

    /**
     * 导出订单购物车中间列表
     */
    @PreAuthorize("@ss.hasPermi('system:order:export')")
    @Log(title = "订单购物车中间", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbShoppingOrder tbShoppingOrder)
    {
        List<TbShoppingOrder> list = tbShoppingOrderService.selectTbShoppingOrderList(tbShoppingOrder);
        ExcelUtil<TbShoppingOrder> util = new ExcelUtil<TbShoppingOrder>(TbShoppingOrder.class);
        util.exportExcel(response, list, "订单购物车中间数据");
    }

    /**
     * 获取订单购物车中间详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:order:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbShoppingOrderService.selectTbShoppingOrderById(id));
    }

    /**
     * 新增订单购物车中间
     */
    @PreAuthorize("@ss.hasPermi('system:order:add')")
    @Log(title = "订单购物车中间", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbShoppingOrder tbShoppingOrder)
    {
        return toAjax(tbShoppingOrderService.insertTbShoppingOrder(tbShoppingOrder));
    }

    /**
     * 修改订单购物车中间
     */
    @PreAuthorize("@ss.hasPermi('system:order:edit')")
    @Log(title = "订单购物车中间", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbShoppingOrder tbShoppingOrder)
    {
        return toAjax(tbShoppingOrderService.updateTbShoppingOrder(tbShoppingOrder));
    }

    /**
     * 删除订单购物车中间
     */
    @PreAuthorize("@ss.hasPermi('system:order:remove')")
    @Log(title = "订单购物车中间", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbShoppingOrderService.deleteTbShoppingOrderByIds(ids));
    }
}
